<!DOCTYPE HTML><html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title><? echo $title ?></title>
    <? require("lib.php"); ?>
</head>
<body>
<div class="content-box">
    <div class="content-box-header">
        <h3><? echo $title ?></h3>
        <div class="clear"></div>
    </div>
    <div class="content-box-content">
        <?
        switch ($do) {
            case "add": add(); break;
            case "update": update($info); break;
            case "delete": delete($id); break;
            default:	show_info($info);
        }
        function show_box($row, $iseditmode, $isadd){
            global $id, $userid, $gee, $baseurl, $h, $refund_reason, $sales_order, $sales_order_detail, $cate, $cateid, $country, $province, $city, $county, $customer, $product, $lang, $code_array,$payment_method, $shipment_method, $arrcurrency, $filter, $baseurl,$express_company, $coupon, $recode, $template;
            $title=$row['sales_order_id'].' - '.ROOT_ORDER_DETAIL;
            // 0 未支付 / 1 已支付 / 2.处理中 / 3 寄送中 / 4 已收到  / 8 客户自己取消  / 9 经销商取消
            $status=$code_array['order_status'];
            $order = $sales_order->get_row($row['sales_order_id'], 'ref_no');
            if($row['refund_reason_id'] == 0){
                $reason = $row['customer_remark'];
            }else{
                $reason_arr = $refund_reason->get_row($row['refund_reason_id'], 'id');
                $reason = $reason_arr['name_'.$lang];
            }
//            $reason = $refund_reason->get_rows(64, 'type', 2);
            $tem=$sales_order_detail->get_rows(64,'sales_order_id',$order['id']);
            $iteming='';
            foreach( $tem as $r ){
                $tempro=$product->get_row($r['product_id']);
                $sku=$tempro['sku'];
                $iteming.=$sku.' * '.$r['quantity'];
                $iteming.='<br />';
            }
            $refund_code_status = $code_array['refund_status'];
            if($row['refund_status']){
                $cstatus=$status[$order['order_status']]['name_'.$lang].'，'.$refund_code_status[$row['refund_status']]['name_'.$lang];
            }else{
                $cstatus=$refund_code_status[$row['refund_status']]['name_'.$lang];
            }
            $bstatus = $status[$row['order_status']]['name_'.$lang];
            $customer_id=$order['customer_id'];
            if($customer_id==0) {
                $customer_name=ROOT_GUEST_ACCOUNT;
                $customer_account = '';
            }else {
                $customer_array=$customer->get_row($customer_id);
                $customer_name=$customer_array['first_name'].$customer_array['last_name'];
                $customer_account = $customer_array['email'];
                if($customer_name=='')$customer_name=$customer_array['nickname'];
            }

            //$country_name=$country->get_name($row['country'],$lang);
            $province_name=$province->get_name($order['province'],$lang);
            $city_name=$city->get_name($order['city'],$lang);
            $county_name=$county->get_name($order['county'],$lang);
            $currency_code=$arrcurrency[$order['currency_id']]['code'];

            // 支付方式 payment_method
            if($order['payment_method_id']==0) $payment_method_name='-';
            else $payment_method_name=$payment_method->get_name($order['payment_method_id'],$lang);

            $shipment_method_name=$shipment_method->get_name($order['shipment_method_id'],$lang);



            echo $h->hidden('userid', $userid);
            echo $h->hidden('id', $row["id"]);
            echo $h->hidden('sales_order_id', $row["sales_order_id"]);
            echo $h->hidden('filter', $filter);
            echo $h->hidden('payment_method_id', $order['payment_method_id']);
            echo $h->hidden('customer_id', $customer_id);
            echo $h->hidden('total_fee', $order['total_price']);
            echo $h->hidden('refund_reason', $reason);

            // express company 物流公司
            $arr_express=array();
            $tem=$express_company->get_rows(128,'is_enabled',1);
            $where_r = array();
            $where_r[] = array('name'=>'template_id', 'val'=>2, 'opn'=>'=', 'and'=>'and');
            $where_r[] = array('name'=>'recode_name', 'val'=>'sales_order_id', 'opn'=>'=', 'and'=>'and');
            $where_r[] = array('name'=>'recode_value', 'val'=>$row['sales_order_id'], 'opn'=>'=', 'and'=>'and');
            $recode_info = $recode->get_rows_advanced(1,$where_r);
            $recode_value = explode('|', $recode_info[0]['value']);
            foreach($tem as $val) $arr_express[$val['id']]=$val;
            ?>
            <table width="99%" cellspacing="0" cellpadding="3" class="mbox">
                <tr class="th"><td class="thtitle" width="25%" align="right"><? echo $title ?></td><td>&nbsp;</td></tr>
                <tr><td class="l"><?=ROOT_ORDER_REFERENCE_NUMBER?></td><td><? echo $row['sales_order_id'] ?></td></tr>
                <tr><td class="l"><?=ROOT_CUSTOMER_NAME?></td><td><? echo $customer_name ?></td></tr>
                <tr><td class="l"><?=ROOT_PRODUCT?></td><td><? echo $iteming ?></td></tr>
                <tr><td class="l"><?=ROOT_AMOUNT?></td><td><? echo $currency_code.' '.$order['total_price']; ?></td></tr>

                <?
                // 优惠券折扣 coupon
                if($order['coupon_discount_amount']>0){
                    $tem=$coupon->get_row($order['coupon_id']);
                    $tem_coupon=$tem['code'];
                    ?>
                    <tr><td class="l"><?=WEB_COUPON_AMOUNT?></td><td><? echo $order['coupon_discount_amount'].' / '.COUPON.': '.$tem_coupon; ?> </td></tr>
                <?}?>
                <?
                // 积分抵扣 point
                if($order['point_discount_amount']>0){
                    $tem_point=$order['point_id'];
                    ?>
                    <tr><td class="l"><?=WEB_POINT_AMOUNT?></td><td><? echo $order['point_discount_amount'].' / '.WEB_POINT_AMOUNT.': '.$tem_point; ?> </td></tr>
                <?}?>

                <tr><td class="l"><?=ROOT_EMAIL?></td><td><? echo $order['email'] ?></td></tr>
                <tr><td class="l"><?=ROOT_RECEIVER?></td><td><? echo $order['contact_name'] ?></td></tr>
                <tr><td class="l"><?=ROOT_RECEIVER_ADDRESS?></td><td><? echo $province_name.$city_name.$county_name.' '.$order['address'].', '.$order['zip'] ?></td></tr>
                <? $nada=''; if(SITE_HAS_INVOICE==0) $nada=' hide '; ?>
                <tr class="<?=$nada?>"><td class="l"><?=ROOT_INVOICE_TO?></td><td><? echo d($order['invoice_header']); ?></td></tr>
                <tr><td class="l"><?=ROOT_PHONE?></td><td><? echo $order['mobile'] ?></td></tr>
                <tr><td class="l"><?=ROOT_CUSTOMER_REMARKS?></td><td><? echo d($order['customer_remark']); ?></td></tr>
                <tr><td class="l"><?=ROOT_ORDER_TIME?></td><td><? echo $order['created_time'] ?></td></tr>

                <tr><td class="l"><?=ROOT_PAYMENT_METHOD?></td><td><? echo $payment_method_name ?></td></tr>
                <? if($order['payment_method_id']==5 || $order['payment_method_id']==6) { ?>
                    <tr><td class="l"><?=ROOT_PAID_TIME?></td><td><? echo $order["paid_time"] ?></td></tr>
                    <tr><td class="l"><?=ROOT_PAYER?></td><td><? echo $order["payer"] ?></td></tr>
                    <tr><td class="l"><?=ROOT_PAYER_ID?></td><td><? echo $order["payer_id"] ?></td></tr>
                    <tr><td class="l"><?=ROOT_PAYMENT_REF_NO?></td><td><? echo $order["payment_ref_no"] ?></td></tr>
                    <tr><td class="l"><?=ROOT_PICTURE?></td><td>
                            <? if(! is_null($order['receipt_doc'])) echo '<a href="../upload/'.$order['receipt_doc'].'" target="_blank"><img src="'.$baseurl.'upload/'.decode($order["receipt_doc"]).'" height="80" /></a><br />'; ?>
<!--                            --><?// echo $h->cfile('cpic', 'g') ?>
                        </td></tr>
                <? } else { ?>
                    <tr><td class="l"><?=ROOT_PAID_TIME?></td><td><? echo $order['paid_time'] ?></td></tr>
                    <tr><td class="l"><?=ROOT_PAYER?></td><td><? echo $order['payer'] ?></td></tr>
                    <tr><td class="l"><?=ROOT_PAYER_ID?></td><td><? echo $order['payer_id'] ?></td></tr>
                    <tr><td class="l"><?=ROOT_PAYMENT_REF_NO?></td><td><? echo $order['payment_ref_no'] ?></td></tr>

                    <? if(! is_null($row['receipt_doc'])){ ?>
                        <tr><td class="l"><?=ROOT_RECEIPT?></td><td><a href="../upload/<?=$order['receipt_doc']?>" target="_blank"><img src="../upload/<?=$order['receipt_doc']?>" height="80" /></a></td></tr>
                    <? }} ?>
                <tr><td class="l"><?=ROOT_SHIPPING_METHOD?></td><td><? echo $shipment_method_name ?></td></tr>
                <tr><td class="l"><?=ROOT_SHIPPING_FEE?></td><td><? echo $currency_code.' '.$order['shipment_cost'] ?></td></tr>
                <tr><td class="l"><?=ROOT_ORDER_DISPATCH_TIME?></td><td><? echo $order["shipped_time"] ?> &nbsp; <?=ROOT_EXAMPLE?>: 2012-9-8 9:41:43</td></tr>
                <tr><td class="l"><?=ROOT_SHIPMENT_COMPANY?></td><td><? echo $arr_express[$order['express']]['name_'.$lang] ?></td></tr>
                <tr><td class="l"><?=ROOT_TRACKING_NUMBER?></td><td><? echo $order["shipment_tracking_no"] ?></td></tr>
                <tr><td class="l"><?=ROOT_ORDER_STATUS?></td><td><? echo $cstatus ?></td></tr>
                <tr><td class="l"><?=ROOT_ORDER_BEFORE_STATUS?></td><td><? echo $bstatus ?></td></tr>
                <tr><td class="l"><?=ROOT_ORDER_IS_CHANGED?></td><td><? if($order['payment_ref_no']) echo ROOT_ORDER_IS_CHANGED_YES;else echo ROOT_ORDER_IS_CHANGED_NO; ?></td></tr>
                <tr><td class="l"><?=ROOT_HANDLING_REMARKS?></td><td><? echo $order["operator_remark"]; ?></td></tr>
                <tr><td class="l"><?=ROOT_ORDER_CANCEL_CUSTOMER_REASON?></td><td><? echo $reason; ?></td></tr>
                <tr><td class="l"><?=ROOT_ORDER_CHECK_STATUS?></td><td><? echo $h->select('refund_status', $row["refund_status"], $refund_code_status, 'id', 'name_'.$lang, 'g') ?></td></tr>
                <tr><td class="l"><?=ROOT_HANDLING_REMARKS?></td><td><? echo $h->text('operator_remark', $row["operator_remark"], 'g'); ?></td></tr>
                <tr class="refund_account hide"><td class="l">退款账号</td><td><? echo $h->text('refund_account', $customer_account, 'g'); ?></td></tr>
                <tr class="refund_amount hide"><td class="l">退款金额</td><td><? echo $h->text('refund_amount', $recode_value[3], 'g'); ?></td></tr>
                <tr><td class="l">&nbsp;</td><td><br><? echo $h->submit('save', '&nbsp; '.ROOT_HANDLE_ORDER.' &nbsp;', $iseditmode==1?' button':'hide') ?>&nbsp; <a onClick="history.go(-1)">[ <?=ROOT_CANCEL?> ]</a><br>
                    </td></tr>
            </table>
        <? } ?>
        <? function show_boxes($result){
            global $page, $pages, $baseurl, $cate, $cateid, $s, $gee, $url, $sales_order, $sales_order_detail, $product, $user, $lang, $country, $code_array, $arrcurrency, $customer, $filter, $h,$payment_method;
            // 构造收款方式数组 arr_payment
            $tem=$payment_method->get_rows(32);
            $arr_payment=array();
            foreach($tem as $val){
                $arr_payment[$val['id']]=$val;
            }
            $str='<table width="99%" class="mlist"><tr>';  // 搜索
            $str.='<td><form action="'.$url.'.php" method="get"><input placeholder="'.ROOT_SEARCH_BY_ORDER_REFERENCE_CUSTOMER_MOBILE.'" name="s" class="g" value="'.$s.'" /> &nbsp; <input class="button_blue" type="submit" value=" '.ROOT_SEARCH.' " /></form></td>';
            $str.='<td '.(($s!='')?"class=\"nada\"":"").' align="right"><form action="'.$url.'.php" method="get">'.$h->select('filter', $filter, $code_array['refund_status'], 'id', 'name_'.$lang, 'g', 'this.form.submit()').'</form></td>';
            $str.='</tr></table>';
            $str.= '<table width="99%" cellspacing="0" cellpadding="3" class="mlist" id="picbox"><tr class="th"><td><strong>#</strong></td><td><strong>'.ROOT_ORDER_REFERENCE_NUMBER.'</strong></td><td><strong>'.ROOT_RECEIVER.'</strong></td><td><strong>'.ROOT_PRODUCT.'</strong></td><td><strong>'.ROOT_AMOUNT.'</strong></td><td><strong>'.ROOT_PAYMENT_METHOD.'</strong></td><td><strong>'.ROOT_ORDER_STATUS.'</strong></td><td><strong>'.ROOT_ORDER_BEFORE_STATUS.'</strong></td><td><strong>'.ROOT_ORDER_TIME.'</strong></td>
		<td><a class="nada" href="'.$url.'.php?a=add">[ '.ROOT_ADD.' ]</a></td></tr>';
            $status=$code_array['order_status'];
            $refund_code_status = $code_array['refund_status'];
            //print_r($refund_code_status);
            $count=1;
            foreach($result as $row)
            {
                //print_r($row);
                $order = $sales_order->get_row($row['sales_order_id'], 'ref_no');
                $tem=$sales_order_detail->get_rows(64,'sales_order_id',$order['id']);
                $iteming='';
                foreach( $tem as $r ){
                    $tempro=$product->get_row($r['product_id']);
                    $sku=$tempro['sku'];
                    $iteming.=$sku.' * '.$r['quantity'];
                    $iteming.='<br />';
                }
                if($row['refund_status']){
                    $cstatus=$status[$order['order_status']]['name_'.$lang].'，'.$refund_code_status[$row['refund_status']]['name_'.$lang];
                }else{
                    $cstatus=$refund_code_status[$row['refund_status']]['name_'.$lang];
                }
                $bstatus = $status[$row['order_status']]['name_'.$lang];
                $customer_id=$order['customer_id'];
                if($customer_id==0) $customer_name=ROOT_GUEST_ACCOUNT;
                else {
                    $customer_array=$customer->get_row($customer_id);
                    $customer_name=$customer_array['email'];
                }
                //$country_name=$country->get_name($row['country'],$lang);
                $currency_code=$arrcurrency[$order['currency_id']]['code'];

                if($order['payment_method_id']==0) $payment_method_name='-';
                else $payment_method_name=$arr_payment[$order['payment_method_id']]['name_'.$lang];

                $id=$row['id'];
                $str.='<tr><td>'.$id.'.</td><td><a href="'.$url.'.php?do=update&id='.$id.(($filter=="")?"":"&filter=".$filter).'">'.decode($row['sales_order_id']).'</a></td><td>'.decode($order['contact_name']).'</td><td>';
                $str.=$iteming.'</td><td>'.$currency_code.' '.$order['total_price'].'</td><td>'.$payment_method_name.'</td><td>'.$cstatus.'</td><td>'.$bstatus.'</td><td>'.$order['created_time'].'</td><td><a href="'.$url.'.php?do=update&id='.$id.(($filter=="")?"":"&filter=".$filter).'">'.ROOT_HANDLE.'</a></td></tr>';
                $count++;
            }
            $str.= "</table>";
            if($count==1) $str.= "<br>".ROOT_NO_DATA."!";
            echo $str;
            echo echo_page_raw($page, $pages, $url.'.php?filter='.$filter.'&page=');
        } ?>
        <br class="clear" />
    </div>
    <br class="clear" />
</div>
<script type="text/javascript">
    $(function(){
        $('select[name="refund_status"]').on('change',function(){
            if($(this).val() == 4){
                $('.refund_account').removeClass('hide');
                $('.refund_amount').removeClass('hide');
            }else{
                $('.refund_account').addClass('hide');
                $('.refund_amount').addClass('hide');
            }
        });
        $('select[name="refund_status"]').triggerHandler('change');
        if($('select[name="refund_status"]').val()==4){
//            $('select[name="refund_status"]').attr('disabled', true);
        }
    });
</script>
</body>
</html>
